home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / g_quake / althome.zip / WEAPONS.QC < prev   
Text File  |  1996-08-04  |  29KB  |  1,386 lines

  1. /*
  2. */
  3. void (entity targ, entity inflictor, entity attacker, float damage) T_Damage;
  4. void () player_run;
  5. void(entity bomb, entity attacker, float rad, entity ignore) T_RadiusDamage;
  6. void(vector org, vector vel, float damage) SpawnBlood;
  7. void() SuperDamageSound;
  8.  
  9. // called by worldspawn
  10. void() W_Precache =
  11. {
  12.     precache_sound ("weapons/r_exp3.wav");    // new rocket explosion
  13.     precache_sound ("weapons/rocket1i.wav");    // spike gun
  14.     precache_sound ("weapons/sgun1.wav");
  15.     precache_sound ("weapons/guncock.wav");    // player shotgun
  16.     precache_sound ("weapons/ric1.wav");    // ricochet (used in c code)
  17.     precache_sound ("weapons/ric2.wav");    // ricochet (used in c code)
  18.     precache_sound ("weapons/ric3.wav");    // ricochet (used in c code)
  19.     precache_sound ("weapons/spike2.wav");    // super spikes
  20.     precache_sound ("weapons/tink1.wav");    // spikes tink (used in c code)
  21.     precache_sound ("weapons/grenade.wav");    // grenade launcher
  22.     precache_sound ("weapons/bounce.wav");        // grenade bounce
  23.     precache_sound ("weapons/shotgn2.wav");    // super shotgun
  24. };
  25.  
  26. float() crandom =
  27. {
  28.     return 2*(random() - 0.5);
  29. };
  30.  
  31. /*
  32. ================
  33. W_FireAxe
  34. ================
  35. */
  36. void() W_FireAxe =
  37. {
  38.     local    vector    source;
  39.     local    vector    org;
  40.  
  41.     source = self.origin + '0 0 16';
  42.     traceline (source, source + v_forward*64, FALSE, self);
  43.     if (trace_fraction == 1.0)
  44.         return;
  45.     
  46.     org = trace_endpos - v_forward*4;
  47.  
  48.     if (trace_ent.takedamage)
  49.     {
  50.         trace_ent.axhitme = 1;
  51.         SpawnBlood (org, '0 0 0', 20);
  52.         T_Damage (trace_ent, self, self, 20);
  53.     }
  54.     else
  55.     {    // hit wall
  56.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  57.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  58.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  59.         WriteCoord (MSG_BROADCAST, org_x);
  60.         WriteCoord (MSG_BROADCAST, org_y);
  61.         WriteCoord (MSG_BROADCAST, org_z);
  62.     }
  63. };
  64.  
  65.  
  66. //============================================================================
  67.  
  68.  
  69. vector() wall_velocity =
  70. {
  71.     local vector    vel;
  72.     
  73.     vel = normalize (self.velocity);
  74.     vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5));
  75.     vel = vel + 2*trace_plane_normal;
  76.     vel = vel * 200;
  77.     
  78.     return vel;
  79. };
  80.  
  81.  
  82. /*
  83. ================
  84. SpawnMeatSpray
  85. ================
  86. */
  87. void(vector org, vector vel) SpawnMeatSpray =
  88. {
  89.     local    entity missile, mpuff;
  90.     local    vector    org;
  91.  
  92.     missile = spawn ();
  93.     missile.owner = self;
  94.     missile.movetype = MOVETYPE_BOUNCE;
  95.     missile.solid = SOLID_NOT;
  96.  
  97.     makevectors (self.angles);
  98.  
  99.     missile.velocity = vel;
  100.     missile.velocity_z = missile.velocity_z + 250 + 50*random();
  101.  
  102.     missile.avelocity = '3000 1000 2000';
  103.     
  104. // set missile duration
  105.     missile.nextthink = time + 1;
  106.     missile.think = SUB_Remove;
  107.  
  108.     setmodel (missile, "progs/zom_gib.mdl");
  109.     setsize (missile, '0 0 0', '0 0 0');        
  110.     setorigin (missile, org);
  111. };
  112.  
  113. /*
  114. ================
  115. SpawnBlood
  116. ================
  117. */
  118. void(vector org, vector vel, float damage) SpawnBlood =
  119. {
  120.     particle (org, vel*0.1, 73, damage*2);
  121. };
  122.  
  123. /*
  124. ================
  125. spawn_touchblood
  126. ================
  127. */
  128. void(float damage) spawn_touchblood =
  129. {
  130.     local vector    vel;
  131.  
  132.     vel = wall_velocity () * 0.2;
  133.     SpawnBlood (self.origin + vel*0.01, vel, damage);
  134. };
  135.  
  136.  
  137. /*
  138. ================
  139. SpawnChunk
  140. ================
  141. */
  142. void(vector org, vector vel) SpawnChunk =
  143. {
  144.     particle (org, vel*0.02, 0, 10);
  145. };
  146.  
  147. /*
  148. ==============================================================================
  149.  
  150. MULTI-DAMAGE
  151.  
  152. Collects multiple small damages into a single damage
  153.  
  154. ==============================================================================
  155. */
  156.  
  157. entity    multi_ent;
  158. float    multi_damage;
  159.  
  160. void() ClearMultiDamage =
  161. {
  162.     multi_ent = world;
  163.     multi_damage = 0;
  164. };
  165.  
  166. void() ApplyMultiDamage =
  167. {
  168.     if (!multi_ent)
  169.         return;
  170.     T_Damage (multi_ent, self, self, multi_damage);
  171. };
  172.  
  173. void(entity hit, float damage) AddMultiDamage =
  174. {
  175.     if (!hit)
  176.         return;
  177.     
  178.     if (hit != multi_ent)
  179.     {
  180.         ApplyMultiDamage ();
  181.         multi_damage = damage;
  182.         multi_ent = hit;
  183.     }
  184.     else
  185.         multi_damage = multi_damage + damage;
  186. };
  187.  
  188. /*
  189. ==============================================================================
  190.  
  191. BULLETS
  192.  
  193. ==============================================================================
  194. */
  195.  
  196. /*
  197. ================
  198. TraceAttack
  199. ================
  200. */
  201. void(float damage, vector dir) TraceAttack =
  202. {
  203.     local    vector    vel, org;
  204.     
  205.     vel = normalize(dir + v_up*crandom() + v_right*crandom());
  206.     vel = vel + 2*trace_plane_normal;
  207.     vel = vel * 200;
  208.  
  209.     org = trace_endpos - dir*4;
  210.  
  211.     if (trace_ent.takedamage)
  212.     {
  213.         SpawnBlood (org, vel*0.2, damage);
  214.         AddMultiDamage (trace_ent, damage);
  215.     }
  216.     else
  217.     {
  218.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  219.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  220.         WriteCoord (MSG_BROADCAST, org_x);
  221.         WriteCoord (MSG_BROADCAST, org_y);
  222.         WriteCoord (MSG_BROADCAST, org_z);
  223.     }
  224. };
  225.  
  226. /*
  227. ================
  228. FireBullets
  229.  
  230. Used by shotgun, super shotgun, and enemy soldier firing
  231. Go to the trouble of combining multiple pellets into a single damage call.
  232. ================
  233. */
  234. void(float shotcount, vector dir, vector spread) FireBullets =
  235. {
  236.     local    vector direction;
  237.     local    vector    src;
  238.     
  239.     makevectors(self.v_angle);
  240.  
  241.     src = self.origin + v_forward*10;
  242.     src_z = self.absmin_z + self.size_z * 0.7;
  243.  
  244.     ClearMultiDamage ();
  245.     while (shotcount > 0)
  246.     {
  247.         direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
  248.  
  249.         traceline (src, src + direction*2048, FALSE, self);
  250.         if (trace_fraction != 1.0)
  251.             TraceAttack (4, direction);
  252.  
  253.         shotcount = shotcount - 1;
  254.     }
  255.     ApplyMultiDamage ();
  256. };
  257.  
  258. /*
  259. ================
  260. W_FireShotgun
  261. ================
  262. */
  263. void() W_FireShotgun =
  264. {
  265.     local vector dir;
  266.  
  267.     sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM);    
  268.  
  269.     self.punchangle_x = -2;
  270.     
  271.     self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  272.     dir = aim (self, 100000);
  273.     FireBullets (6, dir, '0.04 0.04 0');
  274. };
  275.  
  276.  
  277. /*
  278. ================
  279. W_FireSuperShotgun
  280. ================
  281. */
  282. void() W_FireSuperShotgun =
  283. {
  284.     local vector dir;
  285.  
  286.     if (self.currentammo == 1)
  287.     {
  288.         W_FireShotgun ();
  289.         return;
  290.     }
  291.         
  292.     sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM);    
  293.  
  294.     self.punchangle_x = -4;
  295.     
  296.     self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  297.     dir = aim (self, 100000);
  298.     FireBullets (14, dir, '0.14 0.08 0');
  299. };
  300.  
  301.  
  302. /*
  303. ==============================================================================
  304.  
  305. ROCKETS
  306.  
  307. ==============================================================================
  308. */
  309.  
  310. void()    s_explode1    =    [0,        s_explode2] {};
  311. void()    s_explode2    =    [1,        s_explode3] {};
  312. void()    s_explode3    =    [2,        s_explode4] {};
  313. void()    s_explode4    =    [3,        s_explode5] {};
  314. void()    s_explode5    =    [4,        s_explode6] {};
  315. void()    s_explode6    =    [5,        SUB_Remove] {};
  316.  
  317. void() BecomeExplosion =
  318. {
  319.     self.movetype = MOVETYPE_NONE;
  320.     self.velocity = '0 0 0';
  321.     self.touch = SUB_Null;
  322.     setmodel (self, "progs/s_explod.spr");
  323.     self.solid = SOLID_NOT;
  324.     s_explode1 ();
  325. };
  326.  
  327. void() T_MissileTouch =
  328. {
  329.     local float    damg;
  330.  
  331. //    if (other == self.owner)
  332. //        return;        // don't explode on owner
  333.  
  334.     if (pointcontents(self.origin) == CONTENT_SKY)
  335.     {
  336.         remove(self);
  337.         return;
  338.     }
  339.  
  340.     damg = 100 + random()*20;
  341.     
  342.     if (other.health)
  343.     {
  344.         if (other.classname == "monster_shambler")
  345.             damg = damg * 0.5;    // mostly immune
  346.         T_Damage (other, self, self.owner, damg );
  347.     }
  348.  
  349.     // don't do radius damage to the other, because all the damage
  350.     // was done in the impact
  351.     T_RadiusDamage (self, self.owner, 120, other);
  352.  
  353. //    sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  354.     self.origin = self.origin - 8*normalize(self.velocity);
  355.  
  356.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  357.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  358.     WriteCoord (MSG_BROADCAST, self.origin_x);
  359.     WriteCoord (MSG_BROADCAST, self.origin_y);
  360.     WriteCoord (MSG_BROADCAST, self.origin_z);
  361.  
  362.     BecomeExplosion ();
  363. };
  364.  
  365.  
  366.  
  367. /*
  368. ================
  369. W_FireRocket
  370. ================
  371. */
  372. void()   HomeThink;
  373. entity() HomeFindTarget;
  374. float(entity targ) visible;
  375. float(entity targ) infront;
  376.  
  377. void() W_FireRocket =
  378. {
  379.     local    entity missile, mpuff;
  380.     
  381.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  382.     
  383.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  384.  
  385.     self.punchangle_x = -2;
  386.  
  387.     missile = spawn ();
  388.     missile.owner = self;
  389.     missile.movetype = MOVETYPE_FLYMISSILE;
  390.     missile.solid = SOLID_BBOX;
  391.         
  392. // set missile speed    
  393.  
  394.     makevectors (self.v_angle);
  395.     missile.velocity = aim(self, 1000);
  396.     missile.velocity = (missile.velocity * 500);
  397.     missile.angles = vectoangles(missile.velocity);
  398.     
  399.     missile.touch = T_MissileTouch;
  400.     
  401. // set missile duration
  402. //    missile.nextthink = time + 30;
  403. //    missile.think = SUB_Remove;
  404.  
  405.     missile.nextthink = time + 0.2;
  406.     missile.think = HomeThink;
  407.     missile.enemy = world;
  408.  
  409.     setmodel (missile, "progs/missile.mdl");
  410.     setsize (missile, '0 0 0', '0 0 0');        
  411.     setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  412. };
  413.  
  414. /*
  415. =============
  416. Homeinfront (modified from the infront function in ai.qc by chris@ichat.com)
  417.  
  418. returns 1 if the entity is in front (in sight) of self
  419. =============
  420. */
  421. float(entity targ) Homeinfront =
  422. {
  423.     local vector    vec;
  424.     local float        dot;
  425.     
  426.     makevectors (self.angles);
  427.     vec = normalize (targ.origin - self.origin);
  428.     dot = vec * v_forward;
  429.     
  430.     if ( dot > 0.5)  // raise this number for more specific infront
  431.     {
  432.         return TRUE;
  433.     }
  434.     return FALSE;
  435. };
  436.  
  437. entity() HomeFindTarget = 
  438. {
  439.     local entity head, selected;
  440.     local float dist;
  441.     dist = 100000;
  442.     selected = world;
  443.     head = findradius(self.origin, 100000);
  444.     while(head)
  445.     {
  446.         if( (head.health > 1) && (head != self) )
  447.         {
  448.             traceline(self.origin,head.origin,TRUE,self);
  449.             if ( Homeinfront(head) && (trace_fraction >= 1) && (vlen(head.origin - self.origin) < dist) && (head.classname != "door") )
  450.             {
  451.                 selected = head;
  452.                 dist = vlen(head.origin - self.origin);
  453.             }
  454.         }        
  455.         head = head.chain;
  456.     }
  457.     if (selected != world)
  458.     {
  459.         sprint (self.owner,"Homing->");
  460.         if (selected.classname == "player")
  461.         {
  462.             sprint (self.owner,selected.netname);
  463.             sprint (selected,self.owner.netname);
  464.             sprint (selected," has a bogey on you!\n");
  465.         }
  466.         else
  467.             sprint (self.owner,selected.classname);
  468.         sprint (self.owner,"\n");
  469.     }
  470.     return selected;
  471. };
  472.  
  473. void() HomeThink =
  474. {
  475.     local vector dir, vtemp;
  476.  
  477.     self.enemy = HomeFindTarget();
  478.  
  479.     if (self.enemy != world) // Arr.. don't be taken on da World!
  480.     {
  481.         vtemp = self.enemy.origin + '0 0 10';
  482.         dir = normalize(vtemp - self.origin);
  483.         self.velocity = self.velocity + (dir * 500);
  484.         self.angles = vectoangles(self.velocity);
  485.     }
  486.  
  487.     self.nextthink = time + 0.2;
  488.     self.think=HomeThink;
  489. };
  490. /*
  491. ===============================================================================
  492.  
  493. LIGHTNING
  494.  
  495. ===============================================================================
  496. */
  497.  
  498. /*
  499. =================
  500. LightningDamage
  501. =================
  502. */
  503. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  504. {
  505.     local entity        e1, e2;
  506.     local vector        f;
  507.     
  508.     f = p2 - p1;
  509.     normalize (f);
  510.     f_x = 0 - f_y;
  511.     f_y = f_x;
  512.     f_z = 0;
  513.     f = f*16;
  514.  
  515.     e1 = e2 = world;
  516.  
  517.     traceline (p1, p2, FALSE, self);
  518.     if (trace_ent.takedamage)
  519.     {
  520.         particle (trace_endpos, '0 0 100', 225, damage*4);
  521.         T_Damage (trace_ent, from, from, damage);
  522.         if (self.classname == "player")
  523.         {
  524.             if (other.classname == "player")
  525.                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  526.         }
  527.     }
  528.     e1 = trace_ent;
  529.  
  530.     traceline (p1 + f, p2 + f, FALSE, self);
  531.     if (trace_ent != e1 && trace_ent.takedamage)
  532.     {
  533.         particle (trace_endpos, '0 0 100', 225, damage*4);
  534.         T_Damage (trace_ent, from, from, damage);
  535.     }
  536.     e2 = trace_ent;
  537.  
  538.     traceline (p1 - f, p2 - f, FALSE, self);
  539.     if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  540.     {
  541.         particle (trace_endpos, '0 0 100', 225, damage*4);
  542.         T_Damage (trace_ent, from, from, damage);
  543.     }
  544. };
  545.  
  546.  
  547. void() W_FireLightning =
  548. {
  549.     local    vector        org;
  550.  
  551.     if (self.ammo_cells < 1)
  552.     {
  553.         self.weapon = W_BestWeapon ();
  554.         W_SetCurrentAmmo ();
  555.         return;
  556.     }
  557.  
  558. // explode if under water
  559.     if (self.waterlevel > 1)
  560.     {
  561.         T_RadiusDamage (self, self, 35*self.ammo_cells, world);
  562.         self.ammo_cells = 0;
  563.         W_SetCurrentAmmo ();
  564.         return;
  565.     }
  566.  
  567.     if (self.t_width < time)
  568.     {
  569.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  570.         self.t_width = time + 0.6;
  571.     }
  572.     self.punchangle_x = -2;
  573.  
  574.     self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  575.  
  576.     org = self.origin + '0 0 16';
  577.     
  578.     traceline (org, org + v_forward*600, TRUE, self);
  579.  
  580.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  581.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  582.     WriteEntity (MSG_BROADCAST, self);
  583.     WriteCoord (MSG_BROADCAST, org_x);
  584.     WriteCoord (MSG_BROADCAST, org_y);
  585.     WriteCoord (MSG_BROADCAST, org_z);
  586.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  587.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  588.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  589.  
  590.     LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30);
  591. };
  592.  
  593.  
  594. //=============================================================================
  595.  
  596.  
  597. void() GrenadeExplode =
  598. {
  599.     T_RadiusDamage (self, self.owner, 120, world);
  600.  
  601.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  602.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  603.     WriteCoord (MSG_BROADCAST, self.origin_x);
  604.     WriteCoord (MSG_BROADCAST, self.origin_y);
  605.     WriteCoord (MSG_BROADCAST, self.origin_z);
  606.  
  607.     BecomeExplosion ();
  608. };
  609.  
  610. void() GrenadeTouch =
  611. {
  612.     if (other == self.owner)
  613.         return;        // don't explode on owner
  614.     if (other.takedamage == DAMAGE_AIM)
  615.     {
  616.         GrenadeExplode();
  617.         return;
  618.     }
  619.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);    // bounce sound
  620.     if (self.velocity == '0 0 0')
  621.         self.avelocity = '0 0 0';
  622. };
  623.  
  624. /*
  625. ================
  626. W_FireGrenade
  627. ================
  628. */
  629. void() W_FireGrenade =
  630. {
  631.     local    entity missile, mpuff;
  632.     
  633.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  634.     
  635.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  636.  
  637.     self.punchangle_x = -2;
  638.  
  639.     missile = spawn ();
  640.     missile.owner = self;
  641.     missile.movetype = MOVETYPE_BOUNCE;
  642.     missile.solid = SOLID_BBOX;
  643.     missile.classname = "grenade";
  644.         
  645. // set missile speed    
  646.  
  647.     makevectors (self.v_angle);
  648.  
  649.     if (self.v_angle_x)
  650.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  651.     else
  652.     {
  653.         missile.velocity = aim(self, 10000);
  654.         missile.velocity = missile.velocity * 600;
  655.         missile.velocity_z = 200;
  656.     }
  657.  
  658.     missile.avelocity = '300 300 300';
  659.  
  660.     missile.angles = vectoangles(missile.velocity);
  661.     
  662.     missile.touch = GrenadeTouch;
  663.     
  664. // set missile duration
  665.     missile.nextthink = time + 2.5;
  666.     missile.think = GrenadeExplode;
  667.  
  668.     setmodel (missile, "progs/grenade.mdl");
  669.     setsize (missile, '0 0 0', '0 0 0');        
  670.     setorigin (missile, self.origin);
  671. };
  672.  
  673.  
  674. //=============================================================================
  675.  
  676. void() spike_touch;
  677. void() superspike_touch;
  678.  
  679.  
  680. /*
  681. ===============
  682. launch_spike
  683.  
  684. Used for both the player and the ogre
  685. ===============
  686. */
  687. void(vector org, vector dir) launch_spike =
  688. {
  689.     newmis = spawn ();
  690.     newmis.owner = self;
  691.     newmis.movetype = MOVETYPE_FLYMISSILE;
  692.     newmis.solid = SOLID_BBOX;
  693.  
  694.     newmis.angles = vectoangles(dir);
  695.     
  696.     newmis.touch = spike_touch;
  697.     newmis.classname = "spike";
  698.     newmis.think = SUB_Remove;
  699.     newmis.nextthink = time + 6;
  700.     setmodel (newmis, "progs/spike.mdl");
  701.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  702.     setorigin (newmis, org);
  703.  
  704.     newmis.velocity = dir * 1000;
  705. };
  706.  
  707. void() W_FireSuperSpikes =
  708. {
  709.     local vector    dir;
  710.     local entity    old;
  711.     
  712.     sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
  713.     self.attack_finished = time + 0.2;
  714.     self.currentammo = self.ammo_nails = self.ammo_nails - 2;
  715.     dir = aim (self, 1000);
  716.     launch_spike (self.origin + '0 0 16', dir);
  717.     newmis.touch = superspike_touch;
  718.     setmodel (newmis, "progs/s_spike.mdl");
  719.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  720.     self.punchangle_x = -2;
  721. };
  722.  
  723. void(float ox) W_FireSpikes =
  724. {
  725.     local vector    dir;
  726.     local entity    old;
  727.     
  728.     makevectors (self.v_angle);
  729.     
  730.     if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  731.     {
  732.         W_FireSuperSpikes ();
  733.         return;
  734.     }
  735.  
  736.     if (self.ammo_nails < 1)
  737.     {
  738.         self.weapon = W_BestWeapon ();
  739.         W_SetCurrentAmmo ();
  740.         return;
  741.     }
  742.  
  743.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  744.     self.attack_finished = time + 0.2;
  745.     self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  746.     dir = aim (self, 1000);
  747.     launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  748.  
  749.     self.punchangle_x = -2;
  750. };
  751.  
  752.  
  753.  
  754. .float hit_z;
  755. void() spike_touch =
  756. {
  757. local float rand;
  758.     if (other == self.owner)
  759.         return;
  760.  
  761.     if (other.solid == SOLID_TRIGGER)
  762.         return;    // trigger field, do nothing
  763.  
  764.     if (pointcontents(self.origin) == CONTENT_SKY)
  765.     {
  766.         remove(self);
  767.         return;
  768.     }
  769.     
  770. // hit something that bleeds
  771.     if (other.takedamage)
  772.     {
  773.         spawn_touchblood (9);
  774.         T_Damage (other, self, self.owner, 9);
  775.     }
  776.     else
  777.     {
  778.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  779.         
  780.         if (self.classname == "wizspike")
  781.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  782.         else if (self.classname == "knightspike")
  783.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  784.         else
  785.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  786.         WriteCoord (MSG_BROADCAST, self.origin_x);
  787.         WriteCoord (MSG_BROADCAST, self.origin_y);
  788.         WriteCoord (MSG_BROADCAST, self.origin_z);
  789.     }
  790.  
  791.     remove(self);
  792.  
  793. };
  794.  
  795. void() superspike_touch =
  796. {
  797. local float rand;
  798.     if (other == self.owner)
  799.         return;
  800.  
  801.     if (other.solid == SOLID_TRIGGER)
  802.         return;    // trigger field, do nothing
  803.  
  804.     if (pointcontents(self.origin) == CONTENT_SKY)
  805.     {
  806.         remove(self);
  807.         return;
  808.     }
  809.     
  810. // hit something that bleeds
  811.     if (other.takedamage)
  812.     {
  813.         spawn_touchblood (18);
  814.         T_Damage (other, self, self.owner, 18);
  815.     }
  816.     else
  817.     {
  818.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  819.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  820.         WriteCoord (MSG_BROADCAST, self.origin_x);
  821.         WriteCoord (MSG_BROADCAST, self.origin_y);
  822.         WriteCoord (MSG_BROADCAST, self.origin_z);
  823.     }
  824.  
  825.     remove(self);
  826.  
  827. };
  828.  
  829.  
  830. /*
  831. ===============================================================================
  832.  
  833. PLAYER WEAPON USE
  834.  
  835. ===============================================================================
  836. */
  837.  
  838. void() W_SetCurrentAmmo =
  839. {
  840.     player_run ();        // get out of any weapon firing states
  841.  
  842.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  843.     
  844.     if (self.weapon == IT_AXE)
  845.     {
  846.         self.currentammo = 0;
  847.         self.weaponmodel = "progs/v_axe.mdl";
  848.         self.weaponframe = 0;
  849.     }
  850.     else if (self.weapon == IT_SHOTGUN)
  851.     {
  852.         self.currentammo = self.ammo_shells;
  853.         self.weaponmodel = "progs/v_shot.mdl";
  854.         self.weaponframe = 0;
  855.         self.items = self.items | IT_SHELLS;
  856.     }
  857.     else if (self.weapon == IT_SUPER_SHOTGUN)
  858.     {
  859.         self.currentammo = self.ammo_shells;
  860.         self.weaponmodel = "progs/v_shot2.mdl";
  861.         self.weaponframe = 0;
  862.         self.items = self.items | IT_SHELLS;
  863.     }
  864.     else if (self.weapon == IT_NAILGUN)
  865.     {
  866.         self.currentammo = self.ammo_nails;
  867.         self.weaponmodel = "progs/v_nail.mdl";
  868.         self.weaponframe = 0;
  869.         self.items = self.items | IT_NAILS;
  870.     }
  871.     else if (self.weapon == IT_SUPER_NAILGUN)
  872.     {
  873.         self.currentammo = self.ammo_nails;
  874.         self.weaponmodel = "progs/v_nail2.mdl";
  875.         self.weaponframe = 0;
  876.         self.items = self.items | IT_NAILS;
  877.     }
  878.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  879.     {
  880.         self.currentammo = self.ammo_rockets;
  881.         self.weaponmodel = "progs/v_rock.mdl";
  882.         self.weaponframe = 0;
  883.         self.items = self.items | IT_ROCKETS;
  884.     }
  885.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  886.     {
  887.         self.currentammo = self.ammo_rockets;
  888.         self.weaponmodel = "progs/v_rock2.mdl";
  889.         self.weaponframe = 0;
  890.         self.items = self.items | IT_ROCKETS;
  891.     }
  892.     else if (self.weapon == IT_LIGHTNING)
  893.     {
  894.         self.currentammo = self.ammo_cells;
  895.         self.weaponmodel = "progs/v_light.mdl";
  896.         self.weaponframe = 0;
  897.         self.items = self.items | IT_CELLS;
  898.     }
  899.     else
  900.     {
  901.         self.currentammo = 0;
  902.         self.weaponmodel = "";
  903.         self.weaponframe = 0;
  904.     }
  905. };
  906.  
  907. float() W_BestWeapon =
  908. {
  909.     local    float    it;
  910.     
  911.     it = self.items;
  912.  
  913.     if(self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  914.         return IT_LIGHTNING;
  915.     else if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  916.         return IT_SUPER_NAILGUN;
  917.     else if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  918.         return IT_SUPER_SHOTGUN;
  919.     else if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  920.         return IT_NAILGUN;
  921.     else if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  922.         return IT_SHOTGUN;
  923.         
  924. /*
  925.     if(self.ammo_rockets >= 1 && (it & IT_ROCKET_LAUNCHER) )
  926.         return IT_ROCKET_LAUNCHER;
  927.     else if(self.ammo_rockets >= 1 && (it & IT_GRENADE_LAUNCHER) )
  928.         return IT_GRENADE_LAUNCHER;
  929.  
  930. */
  931.  
  932.     return IT_AXE;
  933. };
  934.  
  935. float() W_CheckNoAmmo =
  936. {
  937.     if (self.currentammo > 0)
  938.         return TRUE;
  939.  
  940.     if (self.weapon == IT_AXE)
  941.         return TRUE;
  942.     
  943.     self.weapon = W_BestWeapon ();
  944.  
  945.     W_SetCurrentAmmo ();
  946.     
  947. // drop the weapon down
  948.     return FALSE;
  949. };
  950.  
  951. /*
  952. ============
  953. W_Attack
  954.  
  955. An attack impulse can be triggered now
  956. ============
  957. */
  958. void()    player_axe1;
  959. void()    player_axeb1;
  960. void()    player_axec1;
  961. void()    player_axed1;
  962. void()    player_shot1;
  963. void()    player_nail1;
  964. void()    player_light1;
  965. void()    player_rocket1;
  966.  
  967. void() W_Attack =
  968. {
  969.     local    float    r;
  970.  
  971.     if (!W_CheckNoAmmo ())
  972.         return;
  973.  
  974.     makevectors    (self.v_angle);            // calculate forward angle for velocity
  975.     self.show_hostile = time + 1;    // wake monsters up
  976.  
  977.     if (self.weapon == IT_AXE)
  978.     {
  979.         sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  980.         r = random();
  981.         if (r < 0.25)
  982.             player_axe1 ();
  983.         else if (r<0.5)
  984.             player_axeb1 ();
  985.         else if (r<0.75)
  986.             player_axec1 ();
  987.         else
  988.             player_axed1 ();
  989.         self.attack_finished = time + 0.5;
  990.     }
  991.     else if (self.weapon == IT_SHOTGUN)
  992.     {
  993.         player_shot1 ();
  994.         W_FireShotgun ();
  995.         self.attack_finished = time + 0.5;
  996.     }
  997.     else if (self.weapon == IT_SUPER_SHOTGUN)
  998.     {
  999.         player_shot1 ();
  1000.         W_FireSuperShotgun ();
  1001.         self.attack_finished = time + 0.7;
  1002.     }
  1003.     else if (self.weapon == IT_NAILGUN)
  1004.     {
  1005.         player_nail1 ();
  1006.     }
  1007.     else if (self.weapon == IT_SUPER_NAILGUN)
  1008.     {
  1009.         player_nail1 ();
  1010.     }
  1011.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  1012.     {
  1013.         player_rocket1();
  1014.         W_FireGrenade();
  1015.         self.attack_finished = time + 0.6;
  1016.     }
  1017.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  1018.     {
  1019.         player_rocket1();
  1020.         W_FireRocket();
  1021.         self.attack_finished = time + 0.8;
  1022.     }
  1023.     else if (self.weapon == IT_LIGHTNING)
  1024.     {
  1025.         player_light1();
  1026.         self.attack_finished = time + 0.1;
  1027.         sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  1028.     }
  1029. };
  1030.  
  1031. /*
  1032. ============
  1033. W_ChangeWeapon
  1034.  
  1035. ============
  1036. */
  1037. void() W_ChangeWeapon =
  1038. {
  1039.     local    float    it, am, fl;
  1040.     
  1041.     it = self.items;
  1042.     am = 0;
  1043.     
  1044.     if (self.impulse == 1)
  1045.     {
  1046.         fl = IT_AXE;
  1047.     }
  1048.     else if (self.impulse == 2)
  1049.     {
  1050.         fl = IT_SHOTGUN;
  1051.         if (self.ammo_shells < 1)
  1052.             am = 1;
  1053.     }
  1054.     else if (self.impulse == 3)
  1055.     {
  1056.         fl = IT_SUPER_SHOTGUN;
  1057.         if (self.ammo_shells < 2)
  1058.             am = 1;
  1059.     }        
  1060.     else if (self.impulse == 4)
  1061.     {
  1062.         fl = IT_NAILGUN;
  1063.         if (self.ammo_nails < 1)
  1064.             am = 1;
  1065.     }
  1066.     else if (self.impulse == 5)
  1067.     {
  1068.         fl = IT_SUPER_NAILGUN;
  1069.         if (self.ammo_nails < 2)
  1070.             am = 1;
  1071.     }
  1072.     else if (self.impulse == 6)
  1073.     {
  1074.         fl = IT_GRENADE_LAUNCHER;
  1075.         if (self.ammo_rockets < 1)
  1076.             am = 1;
  1077.     }
  1078.     else if (self.impulse == 7)
  1079.     {
  1080.         fl = IT_ROCKET_LAUNCHER;
  1081.         if (self.ammo_rockets < 1)
  1082.             am = 1;
  1083.     }
  1084.     else if (self.impulse == 8)
  1085.     {
  1086.         fl = IT_LIGHTNING;
  1087.         if (self.ammo_cells < 1)
  1088.             am = 1;
  1089.     }
  1090.  
  1091.     self.impulse = 0;
  1092.     
  1093.     if (!(self.items & fl))
  1094.     {    // don't have the weapon or the ammo
  1095.         sprint (self, "no weapon.\n");
  1096.         return;
  1097.     }
  1098.     
  1099.     if (am)
  1100.     {    // don't have the ammo
  1101.         sprint (self, "not enough ammo.\n");
  1102.         return;
  1103.     }
  1104.  
  1105. //
  1106. // set weapon, set ammo
  1107. //
  1108.     self.weapon = fl;        
  1109.     W_SetCurrentAmmo ();
  1110. };
  1111.  
  1112. /*
  1113. ============
  1114. CheatCommand
  1115. ============
  1116. */
  1117. void() CheatCommand =
  1118. {
  1119.     if (deathmatch || coop)
  1120.         return;
  1121.  
  1122.     self.ammo_rockets = 100;
  1123.     self.ammo_nails = 200;
  1124.     self.ammo_shells = 100;
  1125.     self.items = self.items | 
  1126.         IT_AXE |
  1127.         IT_SHOTGUN |
  1128.         IT_SUPER_SHOTGUN |
  1129.         IT_NAILGUN |
  1130.         IT_SUPER_NAILGUN |
  1131.         IT_GRENADE_LAUNCHER |
  1132.         IT_ROCKET_LAUNCHER |
  1133.         IT_KEY1 | IT_KEY2;
  1134.  
  1135.     self.ammo_cells = 200;
  1136.     self.items = self.items | IT_LIGHTNING;
  1137.  
  1138.     self.weapon = IT_ROCKET_LAUNCHER;
  1139.     self.impulse = 0;
  1140.     W_SetCurrentAmmo ();
  1141. };
  1142.  
  1143. /*
  1144. ============
  1145. CycleWeaponCommand
  1146.  
  1147. Go to the next weapon with ammo
  1148. ============
  1149. */
  1150. void() CycleWeaponCommand =
  1151. {
  1152.     local    float    it, am;
  1153.     
  1154.     it = self.items;
  1155.     self.impulse = 0;
  1156.     
  1157.     while (1)
  1158.     {
  1159.         am = 0;
  1160.  
  1161.         if (self.weapon == IT_LIGHTNING)
  1162.         {
  1163.             self.weapon = IT_AXE;
  1164.         }
  1165.         else if (self.weapon == IT_AXE)
  1166.         {
  1167.             self.weapon = IT_SHOTGUN;
  1168.             if (self.ammo_shells < 1)
  1169.                 am = 1;
  1170.         }
  1171.         else if (self.weapon == IT_SHOTGUN)
  1172.         {
  1173.             self.weapon = IT_SUPER_SHOTGUN;
  1174.             if (self.ammo_shells < 2)
  1175.                 am = 1;
  1176.         }        
  1177.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1178.         {
  1179.             self.weapon = IT_NAILGUN;
  1180.             if (self.ammo_nails < 1)
  1181.                 am = 1;
  1182.         }
  1183.         else if (self.weapon == IT_NAILGUN)
  1184.         {
  1185.             self.weapon = IT_SUPER_NAILGUN;
  1186.             if (self.ammo_nails < 2)
  1187.                 am = 1;
  1188.         }
  1189.         else if (self.weapon == IT_SUPER_NAILGUN)
  1190.         {
  1191.             self.weapon = IT_GRENADE_LAUNCHER;
  1192.             if (self.ammo_rockets < 1)
  1193.                 am = 1;
  1194.         }
  1195.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1196.         {
  1197.             self.weapon = IT_ROCKET_LAUNCHER;
  1198.             if (self.ammo_rockets < 1)
  1199.                 am = 1;
  1200.         }
  1201.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1202.         {
  1203.             self.weapon = IT_LIGHTNING;
  1204.             if (self.ammo_cells < 1)
  1205.                 am = 1;
  1206.         }
  1207.     
  1208.         if ( (self.items & self.weapon) && am == 0)
  1209.         {
  1210.             W_SetCurrentAmmo ();
  1211.             return;
  1212.         }
  1213.     }
  1214.  
  1215. };
  1216.  
  1217. /*
  1218. ============
  1219. ServerflagsCommand
  1220.  
  1221. Just for development
  1222. ============
  1223. */
  1224. void() ServerflagsCommand =
  1225. {
  1226.     serverflags = serverflags * 2 + 1;
  1227. };
  1228.  
  1229. void() QuadCheat =
  1230. {
  1231.     if (deathmatch || coop)
  1232.         return;
  1233.     self.super_time = 1;
  1234.     self.super_damage_finished = time + 30;
  1235.     self.items = self.items | IT_QUAD;
  1236.     dprint ("quad cheat\n");
  1237. };
  1238.  
  1239. /*
  1240. =======================
  1241. ThrowBackpack by Vhold
  1242. =======================
  1243. */
  1244. void() ThrowBackpack =
  1245. {
  1246.     local entity     item;
  1247.  
  1248.     if ( (self.ammo_shells + self.ammo_nails + self.ammo_rockets + self.ammo_cells) == 0)
  1249.         return;
  1250.  
  1251.     item = spawn();
  1252.  
  1253.         if ( self.ammo_shells >= 20)
  1254.     {
  1255.         item.ammo_shells = 20;
  1256.         self.ammo_shells = self.ammo_shells - 20;
  1257.     }
  1258.     else
  1259.     {
  1260.         item.ammo_shells = self.ammo_shells;
  1261.         self.ammo_shells = 0;
  1262.     }
  1263.     
  1264.         if ( self.ammo_nails >= 20)
  1265.     {
  1266.         item.ammo_nails = 20;
  1267.                 self.ammo_nails = self.ammo_nails - 20;
  1268.     }
  1269.     else
  1270.     {
  1271.         item.ammo_nails = self.ammo_nails;
  1272.         self.ammo_nails = 0;
  1273.     }
  1274.  
  1275.     if ( self.ammo_rockets >= 10)
  1276.     {
  1277.         item.ammo_rockets = 10;
  1278.         self.ammo_rockets = self.ammo_rockets - 10;
  1279.     }
  1280.     else
  1281.     {
  1282.         item.ammo_rockets = self.ammo_rockets;
  1283.         self.ammo_nails = 0;
  1284.     }
  1285.  
  1286.     if (self.ammo_cells >= 20)
  1287.     {    
  1288.         item.ammo_cells = 20;
  1289.         self.ammo_cells = self.ammo_cells - 20;
  1290.     }
  1291.     else
  1292.     {
  1293.         item.ammo_cells = self.ammo_cells;
  1294.         self.ammo_cells = 0;
  1295.     }
  1296.  
  1297.     item.owner = self;
  1298.     makevectors(self.v_angle);
  1299.     setorigin(item, self.origin + '0 0 16');
  1300.     item.velocity = aim(self, 1000);
  1301.     item.velocity = item.velocity * 500;
  1302.     item.flags = FL_ITEM;
  1303.     item.solid = SOLID_TRIGGER;
  1304.     item.movetype = MOVETYPE_BOUNCE;
  1305.  
  1306.     setmodel (item, "progs/backpack.mdl");
  1307.     setsize(item, '-16 -16 0', '16 16 56');
  1308.     item.touch = BackpackTouch;
  1309.     item.nextthink = time + 120;    // remove after 2 minutes
  1310.     item.think = SUB_Remove;
  1311.  
  1312.     W_SetCurrentAmmo();
  1313. };
  1314.  
  1315. /*
  1316. ============
  1317. ImpulseCommands
  1318.  
  1319. ============
  1320. */
  1321. void() ImpulseCommands =
  1322. {
  1323.     if (self.impulse >= 1 && self.impulse <= 8)
  1324.         W_ChangeWeapon ();
  1325.  
  1326.     if (self.impulse == 9)
  1327.         CheatCommand ();
  1328.     if (self.impulse == 10)
  1329.         CycleWeaponCommand ();
  1330.     if (self.impulse == 11)
  1331.         ServerflagsCommand ();
  1332.  
  1333.     // Vhold's Backpack thing
  1334.     if (self.impulse == 20)
  1335.         ThrowBackpack();
  1336.  
  1337.     if (self.impulse == 255)
  1338.         QuadCheat ();
  1339.         
  1340.     self.impulse = 0;
  1341. };
  1342.  
  1343. /*
  1344. ============
  1345. W_WeaponFrame
  1346.  
  1347. Called every frame so impulse events can be handled as well as possible
  1348. ============
  1349. */
  1350. void() W_WeaponFrame =
  1351. {
  1352.     if (time < self.attack_finished)
  1353.         return;
  1354.  
  1355.     ImpulseCommands ();
  1356.     
  1357. // check for attack
  1358.     if (self.button0)
  1359.     {
  1360.         SuperDamageSound ();
  1361.         W_Attack ();
  1362.     }
  1363. };
  1364.  
  1365. /*
  1366. ========
  1367. SuperDamageSound
  1368.  
  1369. Plays sound if needed
  1370. ========
  1371. */
  1372. void() SuperDamageSound =
  1373. {
  1374.     if (self.super_damage_finished > time)
  1375.     {
  1376.         if (self.super_sound < time)
  1377.         {
  1378.             self.super_sound = time + 1;
  1379.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1380.         }
  1381.     }
  1382.     return;
  1383. };
  1384.  
  1385.  
  1386.